package mysql

import "fmt"

type Singer struct {
	Id int	`json:"Id"`
	Name string `json:"name"`
	Fans string `json:"fans"`
	Introduce string `json:"introduce"`
	Region string `json:"region"`
	Age string `json:"age"`
	Singer_id int `json:"singer_id" xorm:"int(11) notnull unique 'singer_id'"`
}
//判断是否存在
func (sink MysqlSink) GetSinger(singer_id int)(has bool,err error)  {
	model := new(Singer)
	has, err = sink.database.Where("singer_id=?", singer_id).Get(model)
	if err !=nil{
		fmt.Println(err)
		return
	}
	return has,nil
}
//查询详细信息

func (sink MysqlSink) GetSingerRow(singer_id int)(rows []Singer,err error) {
	//model := new(Singer)
	//has, err = sink.database.Where("singer_id=?", singer_id).Find(model)

	model := make([]Singer, 0)
	err = sink.database.Where(" singer_id = ?", singer_id).Find(&model)
	if err !=nil{
		fmt.Println(err)
		return
	}
	return model,nil
}
//插入数据
func (sink MysqlSink) InsertSinger(data Singer)(res int64,err error)  {
	affected, err :=sink.database.Insert(data)
	if err !=nil{
		fmt.Println(err)
		return
	}
	return affected,nil
}